<template>
  <div>
    <van-nav-bar
      title="首页"
      left-text="退出"
      right-text="新建报名"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-popup
      v-model="addRegisterIsShow"
      closeable
      close-icon-position="top-left"
      position="right"
      :style="{ height: '100%', width: '100%' }"
    >
      <div style="margin-top: 60px">
        <register-form
          :registerParams="profile"
          @handleRegister="handleRegister"
        ></register-form>
      </div>
    </van-popup>
    <van-grid clickable :column-num="2">
      <van-grid-item @click="toGrade">
        <i class="iconfont icon-chengjidan"></i>
        <h4 class="search">成绩查询</h4>
      </van-grid-item>
      <van-grid-item>
        <i class="iconfont icon-zhengshu1"></i>
        <h4 class="search">证书查询</h4>
      </van-grid-item>
    </van-grid>
    <div class="examModel">
      <div class="headTitle">
        <van-icon name="share" />
        <span>个人信息</span>
      </div>
      <div class="person">
        <div class="personMessage">
          <div class="header">
            <div class="left-Message">
              <p>姓名:{{ person.name }}</p>
              <p>手机号码:{{ person.phone }}</p>
              <p>性别:{{ person.gender_display }}</p>
              <p>出生日期:{{ person.birthday }}</p>
            </div>
            <div class="right-Image">
              <van-image
                width="80"
                height="100"
                :src="
                  person.photo
                    ? person.photo + '?' + new Date()
                    : 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png'
                "
              />
            </div>
          </div>
        </div>
        <div class="footer">
          <p>证件类型:{{ person.card_type_display }}</p>
          <p>证件号码:{{ person.card_id }}</p>
          <p>家庭住址:{{ person.address }}</p>
        </div>
      </div>
    </div>
    <div class="examModel">
      <div class="headTitle">
        <van-icon name="share" />
        <span>报考信息</span>
      </div>
      <div class="profileCard">
        <van-card v-for="item in profile" :key="item.id">
          <template #title>
            <div
              style="
                width: 100%;
                display: flex;
                justify-content: space-between;
                margin-bottom: 5px;
              "
            >
              <div style="display: flex">
                <van-button
                  size="mini"
                  v-if="item.contract_id"
                  @click="lookTransation(item.contract_id)"
                  >查看合同</van-button
                >
                <van-button
                  size="mini"
                  v-if="item.contract_id"
                  @click="toTransation(item)"
                  >重签合同</van-button
                >
              </div>
              <div></div>
              <van-button
                size="mini"
                :disabled="
                  item.state_code < 3 || (item.state_code < 7 && item.exam_date)
                    ? false
                    : true
                "
                @click="updateExam(item.id)"
                >编辑信息</van-button
              >
            </div>
            <van-popup
              v-model="updateMessageIsShow"
              closeable
              close-icon-position="top-left"
              position="right"
              :style="{ height: '100%', width: '100%' }"
            >
              <div style="margin-top: 60px">
                <van-form scroll-to-error @submit="updateSubmit">
                  <div>
                    <van-field
                      v-model="form.name"
                      label="姓名"
                      :disabled="true"
                      placeholder="姓名"
                      :rules="[{ required: true, message: '请填写姓名' }]"
                    />
                    <van-field
                      v-model="form.last_py"
                      label="姓拼音"
                      placeholder="姓拼音"
                      :rules="[{ required: true, message: '请输入姓拼音' }]"
                    />
                    <van-field
                      v-model="form.first_py"
                      label="名拼音"
                      placeholder="名拼音"
                      :rules="[{ required: true, message: '请输入名拼音' }]"
                    />
                    <van-cell>
                      <div style="display: flex; color: #c8c9cc">
                        <span style="width: 6.2em; margin-right: 12px"
                          >性别</span
                        >
                        <van-radio-group
                          :disabled="true"
                          v-model="form.gender"
                          direction="horizontal"
                        >
                          <van-radio name="m">男</van-radio>
                          <van-radio name="f">女</van-radio>
                        </van-radio-group>
                      </div>
                    </van-cell>
                    <van-field
                      readonly
                      clickable
                      :value="form.birthday"
                      :disabled="true"
                      label="出生日期"
                      placeholder="点击选择出生日期"
                      @click="birthdayIsShow = true"
                      :rules="[{ required: true, message: '请选择出生日期' }]"
                    />
                    <van-popup v-model="birthdayIsShow" round position="bottom">
                      <van-datetime-picker
                        v-model="date.currentDate"
                        type="date"
                        title="选择年月日"
                        :min-date="date.minDate"
                        :max-date="date.maxDate"
                        @confirm="onConfirmBirthdayUpdate"
                        @cancel="onCancelBirthday"
                      />
                    </van-popup>
                    <van-field
                      :value="cardTypeUpdate"
                      is-link
                      readonly
                      :disabled="true"
                      label="证件类型"
                      placeholder="请选择证件类型"
                      @click="cardTypeIsShow = true"
                    />
                    <van-popup v-model="cardTypeIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="name"
                        @confirm="onConfirmCardTypeUpdate"
                        @cancel="onCancelCardType"
                        :columns="cardOptions"
                      />
                    </van-popup>
                    <van-field
                      :disabled="true"
                      v-model="form.card_id"
                      label="证件号码"
                      placeholder="证件号码"
                      :rules="[
                        {
                          required: true,
                          pattern:
                            form.card_type == 1
                              ? cardIdRule
                              : /^[A-Z,a-z,\d]+$/,
                          message: '格式错误',
                        },
                      ]"
                    />
                    <van-field
                      label="电子邮箱"
                      :disabled="true"
                      v-model="form.email"
                      placeholder="电子邮箱"
                      :rules="[
                        { pattern: emailRule, message: '请输入正确内容' },
                      ]"
                    />
                    <van-popup v-model="earaIsShow" round position="bottom">
                      <van-area
                        title="所在城市"
                        :area-list="areaList"
                        :columns-num="2"
                        value="110101"
                        @confirm="onConfirmAreaUpdate"
                        @cancel="earaIsShow = false"
                      />
                    </van-popup>

                    <!-- <van-cell>
                                            <div style="display: flex">
                                                <span style="width:6.2em;margin-right: 12px">是否购书</span>
                                                <van-radio-group v-model="form.buy_book" direction="horizontal">
                                                    <van-radio :name="false">否</van-radio>
                                                    <van-radio :name="true">是</van-radio>
                                                </van-radio-group>
                                            </div>
                                        </van-cell> -->
                    <!-- <van-field
                                                v-model="form.address"
                                                rows="1"
                                                autosize
                                                label="居住地"
                                                type="textarea"
                                                maxlength="30"
                                                placeholder="请输入居住地"
                                                show-word-limit
                                                :rules="[{ required: true, message: '请填写居住地' }]"
                                        /> -->
                  </div>
                  <div>
                    <!-- <van-field
                                                v-model="form.school"
                                                label="毕业学校"
                                                placeholder="请输入毕业学校"
                                                show-word-limit
                                                :rules="[{ required: true, message: '请填写毕业学校' }]"
                                        /> -->
                    <van-field
                      readonly
                      clickable
                      :disabled="true"
                      :value="form.grad_time"
                      label="毕业时间"
                      placeholder="点击选择毕业时间"
                      @click="gradTimeIsShow = true"
                      :rules="[{ required: true, message: '请选择毕业时间' }]"
                    />
                    <van-popup v-model="gradTimeIsShow" round position="bottom">
                      <van-datetime-picker
                        v-model="date.currentDate"
                        type="date"
                        title="选择年月日"
                        :min-date="date.minDate"
                        :max-date="date.maxDate"
                        @confirm="onConfirmGradTimeUpdate"
                        @cancel="onCancelExamDate"
                      />
                    </van-popup>
                    <van-field
                      v-model="form.hig_edu"
                      is-link
                      readonly
                      :disabled="true"
                      label="最高学历"
                      placeholder="请选择最高学历"
                      @click="higEduIsShow = true"
                    />
                    <van-popup v-model="higEduIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="name"
                        @confirm="onConfirmHigEduUpdate"
                        @cancel="onCancelHigEdu"
                        :columns="higEduOptions"
                      />
                    </van-popup>
                    <!-- <van-field
                                                v-model="form.major"
                                                label="专业门类"
                                                placeholder="请输入专业门类"
                                                show-word-limit
                                                :rules="[{ required: true, message: '请输入专业门类' }]"
                                        /> -->
                    <van-field
                      v-model="form.work_age"
                      type="number"
                      label="从业年限"
                      :disabled="true"
                      placeholder="请输入从业年限"
                      show-word-limit
                      :rules="[{ required: true, message: '请输入从业年限' }]"
                    />
                    <!-- <van-field
                                                v-model="form.work_title"
                                                label="现有职称"
                                                placeholder="请输入现有职称"
                                                show-word-limit
                                                :rules="[{ required: true, message: '请输入现有职称' }]"
                                        /> -->
                    <van-field
                      v-model="form.com_name"
                      label="单位名称"
                      placeholder="没有工作填写 “无” "
                      :rules="[{ required: true, message: '请填写单位名称' }]"
                    />
                    <van-field
                      readonly
                      clickable
                      :value="
                        `${form.province == null ? '':form.province}/${form.city == null ? '':form.city}/${form.dis == null ? '':form.dis}`
                      "
                      label="工作区域"
                      placeholder="点击选择工作区域"
                      @click="earaIsShow = true"
                      :rules="[{ required: true, message: '请选择工作区域' }]"
                    />
                    <van-popup v-model="earaIsShow" round position="bottom">
                      <van-area
                        title="工作区域"
                        :area-list="areaList"
                        :columns-num="3"
                        value="110101"
                        @confirm="onConfirmArea"
                        @cancel="earaIsShow = false"
                      />
                    </van-popup>
                    <van-field
                      :value="work_dutyName"
                      is-link
                      readonly
                      label="现有职务"
                      :rules="[{ required: true, message: '请选择现有职务' }]"
                      placeholder="请选择现有职务"
                      @click="work_dutyIsShow = true"
                    />
                    <van-popup
                      v-model="work_dutyIsShow"
                      round
                      position="bottom"
                    >
                      <van-picker
                        show-toolbar
                        value-key="name"
                        @confirm="onConfirmWorkDuty"
                        @cancel="work_dutyIsShow = false"
                        :columns="workDutyOptions"
                      />
                    </van-popup>
                    <van-field
                      :value="indTypeName"
                      is-link
                      readonly
                      label="行业类型"
                      :rules="[{ required: true, message: '请选择行业类型' }]"
                      placeholder="请选择行业类型"
                      @click="ind_typeIsShow = true"
                    />
                    <van-popup v-model="ind_typeIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="name"
                        @confirm="onConfirmIndType"
                        @cancel="ind_typeIsShow = false"
                        :columns="indTypeOptions"
                      />
                    </van-popup>
                    <van-field
                      :value="comTypeName"
                      is-link
                      readonly
                      label="单位类型"
                      :rules="[{ required: true, message: '请选择单位类型' }]"
                      placeholder="请选择单位类型"
                      @click="com_typeIsShow = true"
                    />
                    <van-popup v-model="com_typeIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="name"
                        @confirm="onConfirmComType"
                        @cancel="com_typeIsShow = false"
                        :columns="comTypeOptions"
                      />
                    </van-popup>

                    <!-- <vant-img-upload :fileUrl="form.photo == '' ? '' : form.photo.split('?')[0] == 'null' ? '':form.photo" @vantUpload="vantUploadUpdate"></vant-img-upload> -->
                    <van-field
                      readonly
                      clickable
                      label="考试城市"
                      :value="form.exam_city"
                      placeholder="选择考试城市"
                      @click="examCityIsShow = true"
                      :rules="[{ required: true, message: '请选择考试城市' }]"
                    />
                    <van-popup v-model="examCityIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="exam_city"
                        :columns="examCityOptions"
                        @cancel="examCityIsShow = false"
                        @confirm="onConfirmExamCityUpdate"
                      />
                    </van-popup>
                    <van-field
                      readonly
                      clickable
                      label="考试时间"
                      :value="form.exam_date"
                      placeholder="选择考试时间"
                      @click="examDateIsShow = true"
                      :rules="[{ required: true, message: '请选择考试时间' }]"
                    />
                    <van-popup v-model="examDateIsShow" round position="bottom">
                      <van-picker
                        show-toolbar
                        value-key="exam_date"
                        :columns="examDateOptions"
                        @cancel="examDateIsShow = false"
                        @confirm="onConfirmExamDateUpdate"
                      />
                    </van-popup>
                  </div>
                  <div style="margin: 16px">
                    <van-button round block type="info" native-type="submit"
                      >提交</van-button
                    >
                  </div>
                </van-form>
              </div>
            </van-popup>
            <div style="display: flex">
              <div>
                <span class="examTitle"
                  >报考信息:<span class="examCourseName">{{
                    item.course.name
                  }}</span></span
                >
                <div style="margin-left: 10px">
                  <p v-if="item.exam_city">
                    考试城市:<span>{{ item.exam_city }}</span>
                  </p>
                  <p v-if="item.exam_date">考试时间: {{ item.exam_date }}</p>
                  <!-- <p>购买教程: {{ item.buy_book ? "已购买" : "未购买" }}</p> -->
                  <p>
                    审核状态:
                    <span
                      :style="
                        item.state_code == 8 ? 'color:green' : 'color:orange'
                      "
                      >{{ state_map[item.state_code] }}</span
                    >
                  </p>
                  <p v-if="isReject[item.state_code].includes('reject')">
                    备注信息:
                    <span
                      style="color: red"
                      v-if="isReject[item.state_code].includes('reject')"
                      v-text="item.note.replace('<已编辑>', '')"
                    ></span>
                  </p>
                </div>
              </div>
              <div style="margin-left: 10px">
                <span class="examTitle"
                  >报考机构:<span class="examCourseName"
                    >{{ item.org.org_name }}({{ item.org.org_code }})</span
                  ></span
                >
                <div style="margin-left: 10px">
                  <p v-if="item.gaodun_u">
                    账号信息:{{ item.gaodun_u }} --- {{ item.gaodun_p }}
                  </p>
                  <p v-if="item.exp_date">账号期限:{{ item.exp_date }}</p>
                  <p v-if="item.exam_code == null ? false : true">
                    准考证号:<span v-if="item.exam_list[item.exam_list.length - 1]['is_pass'] == true || item.exam_list[item.exam_list.length - 1]['is_pass'] == null" style="color: green">{{
                      item.exam_code
                    }}</span>
                  </p>
                </div>
              </div>
            </div>
          </template>

          <template #footer>
            <van-button
              v-if="
                (!item.school && !item.exam_date && item.state_code > 3) ||
                (item.exam_list[item.exam_list.length - 1] &&
                  item.exam_list[item.exam_list.length - 1]['is_pass'] ===
                    false)
              "
              size="mini"
              @click="toExam(item.id)"
            >
              {{
                item.exam_list[item.exam_list.length - 1] &&
                item.exam_list[item.exam_list.length - 1]["is_pass"] === false
                  ? "点击补考"
                  : "点击报考"
              }}
            </van-button>
          </template>
        </van-card>
        <van-popup
          v-model="goExamIsShow"
          closeable
          close-icon-position="top-left"
          position="right"
          :style="{ height: '100%', width: '100%' }"
        >
          <div style="margin-top: 60px">
            <!-- <van-steps :active="active">
              <van-step>步骤 1</van-step>
              <van-step>步骤 2</van-step>
              <van-step>步骤 3</van-step>
            </van-steps> -->
            <div>
              <van-form
                ref="examForm"
                @failed="onExamFailed"
                @submit="onExamSubmit"
              >
                <div v-show="active == 0">
                  <van-field
                    v-model="examForm.name"
                    name="name"
                    :disabled="true"
                    label="姓名"
                    placeholder="姓名"
                    :rules="[{ required: true, message: '请填写姓名' }]"
                  />
                  <van-field
                    :disabled="true"
                    v-model="examForm.last_py"
                    name="last_py"
                    label="姓拼音"
                    placeholder="姓拼音"
                    :rules="[{ required: true, message: '请输入姓拼音' }]"
                  />
                  <van-field
                    :disabled="true"
                    v-model="examForm.first_py"
                    name="first_py"
                    label="名拼音"
                    placeholder="名拼音"
                    :rules="[{ required: true, message: '请输入名拼音' }]"
                  />
                  <van-field
                    :value="cardType"
                    is-link
                    readonly
                    :disabled="true"
                    label="证件类型"
                    placeholder="请选择证件类型"
                    @click="cardTypeIsShow = true"
                  />
                  <van-popup v-model="cardTypeIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="name"
                      @confirm="onConfirmCardType"
                      @cancel="onCancelCardType"
                      :columns="cardOptions"
                    />
                  </van-popup>
                  <van-field
                    v-model="examForm.card_id"
                    :disabled="true"
                    label="证件号码"
                    placeholder="证件号码"
                    :rules="[
                      {
                        required: true,
                        pattern:
                          examForm.card_type == 1
                            ? cardIdRule
                            : /^[A-Z,a-z,\d]+$/,
                        message: '格式错误',
                      },
                    ]"
                  />
                  <van-field
                    readonly
                    clickable
                    :disabled="true"
                    :value="examForm.birthday"
                    label="出生日期"
                    placeholder="点击选择出生日期"
                    @click="birthdayIsShow = true"
                    :rules="[{ required: true, message: '请选择出生日期' }]"
                  />
                  <van-popup v-model="birthdayIsShow" round position="bottom">
                    <van-datetime-picker
                      v-model="date.currentDate"
                      type="date"
                      title="选择年月日"
                      :min-date="date.minDate"
                      :max-date="date.maxDate"
                      @confirm="onConfirmBirthday"
                      @cancel="onCancelBirthday"
                    />
                  </van-popup>
                  <!-- <van-field
                    v-model="examForm.address"
                    rows="1"
                    name="address"
                    autosize
                    label="家庭住址"
                    type="textarea"
                    maxlength="30"
                    placeholder="请输入家庭住址"
                    show-word-limit
                    :rules="[{ required: true, message: '请填写家庭住址' }]"
                  /> -->
                  <!-- <van-field
                    v-model="examForm.school"
                    name="school"
                    label="毕业学校"
                    placeholder="请输入毕业学校"
                    show-word-limit
                    :rules="[{ required: true, message: '请填写毕业学校' }]"
                  /> -->
                  <van-field
                    readonly
                    clickable
                    :disabled="true"
                    name="grad_time"
                    :value="examForm.grad_time"
                    label="毕业时间"
                    placeholder="点击选择毕业时间"
                    @click="gradTimeIsShow = true"
                    :rules="[{ required: true, message: '请选择毕业时间' }]"
                  />
                  <van-popup v-model="gradTimeIsShow" round position="bottom">
                    <van-datetime-picker
                      v-model="date.currentDate"
                      type="date"
                      title="选择年月日"
                      :min-date="date.minDate"
                      :max-date="date.maxDate"
                      @confirm="onConfirmGradTime"
                      @cancel="onCancelExamDate"
                    />
                  </van-popup>
                  <van-field
                    v-model="examForm.hig_edu"
                    is-link
                    name="hig_edu"
                    readonly
                    :disabled="true"
                    label="最高学历"
                    placeholder="请选择最高学历"
                    @click="higEduIsShow = true"
                    :rules="[{ required: true, message: '请选择最高学历' }]"
                  />
                  <van-popup v-model="higEduIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="name"
                      @confirm="onConfirmHigEdu"
                      @cancel="onCancelHigEdu"
                      :columns="higEduOptions"
                    />
                  </van-popup>
                  <!-- <van-field
                    v-model="examForm.major"
                    name="major"
                    label="专业门类"
                    placeholder="请输入专业门类"
                    show-word-limit
                    :rules="[{ required: true, message: '请输入专业门类' }]"
                  /> -->
                </div>
                <van-field
                  name="work_age"
                  v-model="examForm.work_age"
                  type="number"
                  :disabled="true"
                  label="从业年限"
                  placeholder="请输入从业年限"
                  show-word-limit
                  :rules="[{ required: true, message: '请输入从业年限' }]"
                />
                <div>
                  <van-field
                    v-model="examForm.com_name"
                    name="com_name"
                    label="单位名称"
                    placeholder="请输入单位名称"
                    show-word-limit
                    :rules="[{ required: true, message: '请输入单位名称' }]"
                  />
                  <!-- <van-field
                    v-model="examForm.work_title"
                    name="work_title"
                    label="现有职称"
                    placeholder="请输入现有职称"
                    show-word-limit
                    :rules="[{ required: true, message: '请输入现有职称' }]"
                  /> -->
                  <van-field
                    :value="work_dutyNameExam"
                    is-link
                    readonly
                    label="现有职务"
                    :rules="[{ required: true, message: '请选择现有职务' }]"
                    placeholder="请选择现有职务"
                    @click="work_dutyIsShow = true"
                  />
                  <van-popup v-model="work_dutyIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="name"
                      @confirm="onConfirmWorkDutyExam"
                      @cancel="work_dutyIsShow = false"
                      :columns="workDutyOptions"
                    />
                  </van-popup>
                  <van-field
                    :value="indTypeNameExam"
                    is-link
                    readonly
                    label="行业类型"
                    :rules="[{ required: true, message: '请选择行业类型' }]"
                    placeholder="请选择行业类型"
                    @click="ind_typeIsShow = true"
                  />
                  <van-popup v-model="ind_typeIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="name"
                      @confirm="onConfirmIndTypeExam"
                      @cancel="ind_typeIsShow = false"
                      :columns="indTypeOptions"
                    />
                  </van-popup>
                  <van-field
                    :value="comTypeNameExam"
                    is-link
                    readonly
                    label="单位类型"
                    :rules="[{ required: true, message: '请选择单位类型' }]"
                    placeholder="请选择单位类型"
                    @click="com_typeIsShow = true"
                  />
                  <van-popup v-model="com_typeIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="name"
                      @confirm="onConfirmComTypeExam"
                      @cancel="com_typeIsShow = false"
                      :columns="comTypeOptions"
                    />
                  </van-popup>
                </div>
                <div>
                  <van-field
                    v-model="examForm.exam_org_code"
                    label="机构代码"
                    placeholder="请输入机构代码"
                    show-word-limit
                    :rules="[{ required: true, message: '请输入机构代码' }]"
                  />
                  <van-field
                    readonly
                    clickable
                    label="考试城市"
                    :value="examForm.exam_city"
                    placeholder="选择考试城市"
                    @click="examCityIsShow = true"
                    :rules="[{ required: true, message: '请选择考试城市' }]"
                  />
                  <van-popup v-model="examCityIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="exam_city"
                      :columns="examCityOptions"
                      @cancel="examCityIsShow = false"
                      @confirm="onConfirmExamCity"
                    />
                  </van-popup>
                  <van-field
                    readonly
                    clickable
                    label="考试时间"
                    :value="examForm.exam_date"
                    placeholder="选择考试时间"
                    @click="examDateIsShow = true"
                    :rules="[{ required: true, message: '请选择考试时间' }]"
                  />
                  <van-popup v-model="examDateIsShow" round position="bottom">
                    <van-picker
                      show-toolbar
                      value-key="exam_date"
                      :columns="examDateOptions"
                      @cancel="examDateIsShow = false"
                      @confirm="onConfirmExamDate"
                    />
                  </van-popup>
                  <!-- <vant-img-upload
                    :fileUrl="fileUrl"
                    @vantUpload="vantUpload"
                  ></vant-img-upload> -->
                  <van-field
                    label="手机号码"
                    v-model="examForm.phone"
                    placeholder="请输入手机号码"
                    :rules="[
                      { pattern: phoneRule, message: '手机号码格式错误' },
                    ]"
                  />
                  <van-field
                    v-model="examForm.code"
                    name="code"
                    center
                    clearable
                    placeholder="请输入短信验证码"
                    :rules="[
                      { pattern: codeRule, message: '短信验证码长度为四位' },
                    ]"
                  >
                    <template #button>
                      <tencent-captcha
                        ref="captcha"
                        :phone="examForm.phone"
                        :phoneRule="phoneRule"
                        scene="2"
                      ></tencent-captcha>
                    </template>
                  </van-field>
                  <van-cell v-if="examForm.course.name.includes('薪酬管理')">
                    <van-checkbox v-model="examForm.is_train" shape="square"
                      ><a href="#" style="color: #e6a23c"
                        >请勾选并确认是否参加培训</a
                      ></van-checkbox
                    >
                  </van-cell>
                </div>
                <van-cell>
                  <van-checkbox v-model="checked" shape="square">
                    本人已阅读并同意<a href="#" @click="isPrivacyFun">《隐私政策》</a><a href="#" @click="isRegisterFun">《用户注册协议》</a>
                  </van-checkbox>
                </van-cell>

                <van-button
                  style="margin-top: 20px; width: 90%; margin: 0 auto"
                  round
                  block
                  type="info"
                  native-type="submit"
                  >提交</van-button
                >
              </van-form>
            </div>
            <!-- <div class="examButton">
              <van-button
                type="info"
                v-if="active > 0 && active < 3"
                @click="pre"
                >上一步</van-button
              >
              <van-button type="info" v-if="active < 2" @click="next"
                >下一步</van-button
              >
            </div> -->
          </div>
        </van-popup>
      </div>
    </div>
  </div>
</template>

<script>
import TencentCaptcha from "../../../components/TencentCaptcha/TencentCaptcha";
import vantImgUpload from "./components/vantImgUpload";
import registerForm from "./components/registerForm";
import { Dialog, Notify, Toast } from "vant";
import "@/assets/icon/iconfont.css";
import {
  get_n_Org,
  getProfile,
  examDateByCourseId,
  exam_reg,
  editContent,
  signContract,
  generateContract,
  viewContract,
  getOrg,
} from "../../../request/api";
import { formatDate } from "../util/date";
import { areaList } from "@vant/area-data";
export default {
  name: "index",
  data() {
    return {
      certDisplayOptions: [
        { id: 0, name: "没有任何证书" },
        { id: 1, name: "人力资源管理师一级" },
        { id: 2, name: "人力资源管理师二级" },
        { id: 3, name: "人力资源管理师三级" },
        { id: 4, name: "人力资源管理师四级" },
        { id: 5, name: "税务师" },
        { id: 6, name: "注册会计师" },
        { id: 7, name: "会计师高级" },
        { id: 8, name: "会计师中级" },
        { id: 9, name: "会计师初级" },
        { id: 10, name: "经济师高级" },
        { id: 11, name: "经济师中级" },
        { id: 12, name: "经济师初级" },
        { id: 13, name: "律师" },
        { id: 14, name: "ACCA" },
        { id: 15, name: "AICPA" },
        { id: 16, name: "IFA" },
        { id: 17, name: "ATHE国际薪税师二级（中级）" },
        { id: 18, name: "ATHE国际薪税师三级（初级）" },
        { id: 19, name: "CMA", 20: "CIMA" },
      ],
      work_dutyIsShow: false,
      ind_typeIsShow: false,
      com_typeIsShow: false,
      comTypeOptions: [
        { name: "事业单位", value: 1 },
        { name: "人力资源服务机构", value: 2 },
        { name: "会计（税务,律师）事务所", value: 3 },
        { name: "其他中介机构", value: 4 },
        { name: "金融机构（银行,证券,保险,信托,基金等）", value: 5 },
        { name: "院校", value: 6 },
        { name: "其他", value: 7 },
      ],
      indTypeOptions: [
        { name: "集成电路", value: 1 },
        { name: "人工智能", value: 2 },
        { name: "软件与平台", value: 3 },
        { name: "生命与科学", value: 4 },
        { name: "生物医药", value: 5 },
        { name: "医疗保健", value: 6 },
        { name: "航空宇航天", value: 7 },
        { name: "汽车", value: 8 },
        { name: "化工", value: 9 },
        { name: "工业产品和服务", value: 10 },
        { name: "消费品", value: 11 },
        { name: "能源和自然资源", value: 12 },
        { name: "金融", value: 13 },
        { name: "基础建设和建筑产品", value: 14 },
        { name: "机械和设备", value: 15 },
        { name: "媒体", value: 16 },
        { name: "金属和矿业", value: 17 },
        { name: "私募基金", value: 18 },
        { name: "零售", value: 19 },
        { name: "高科技", value: 20 },
        { name: "电信", value: 21 },
        { name: "公用事业", value: 22 },
        { name: "教育", value: 23 },
        { name: "文化", value: 24 },
        { name: "人力资源与人力资本服务", value: 25 },
        { name: "其他", value: 26 },
        { name: "无", value: 27 },
      ],
      workDutyOptions: [
        {
          name: "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）",
          value:
            "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）Head of the firm / Senior Management (Chairman / Equity Partners / Salaried Partners, etc.)",
        },
        {
          name: "单位负责人/高级管理人员（董事长/总裁/副总裁等）",
          value:
            "单位负责人/高级管理人员（董事长/总裁/副总裁等）Person in charge / Senior Management (Chairman / President / Vice President, etc.)",
        },
        {
          name: "人力资源部（薪酬专员岗/薪税服务专员岗）",
          value:
            "人力资源部（薪酬专员岗/薪税服务专员岗）Human Resources Dept. (Payments Specialist Post/Payments and Tax Service Specialist Post)",
        },
        {
          name: "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）",
          value:
            "人力资源部（薪酬经理岗/薪税服务经理岗）Human Resources Dept. (Payments Manager Post/Payments and Tax Service Manager Post)",
        },
        {
          name: "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）",
          value:
            "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）Human Resources Dept. (Payments Director Post and above/Payments and Tax Service Director Post and above)",
        },
        {
          name: "财务部（专员岗）",
          value: "财务部（专员岗）Finance Dept. (Specialist Post)",
        },
        {
          name: "财务部（经理岗）",
          value: "财务部（经理岗）Finance Dept. (Manager Post)",
        },
        {
          name: "财务部（总监岗及以上）",
          value:
            "财务部（总监岗及以上）Finance Dept. (Director Post and above)",
        },
        {
          name: "其他未列明部门（专员岗）",
          value:
            "其他未列明部门（专员岗）Other Unspecified Departments (Specialist Post)",
        },
        {
          name: "其他未列明部门（经理岗）",
          value:
            "其他未列明部门（经理岗）Other Unspecified Departments (Manager Post)",
        },
        {
          name: "其他未列明部门（总监岗及以上）",
          value:
            "其他未列明部门（总监岗及以上）Other Unspecified Departments (Director Post and above)",
        },
        {
          name: "客服部/市场部/业务部（专员岗）",
          value:
            "客服部/市场部/业务部（专员岗）Customer Service Dept. / Marketing Dept. / Business Dept. (Specialist Post)",
        },
        {
          name: "客服部/市场部/业务部（经理岗）",
          value:
            "客服部/市场部/业务部（经理岗）Customer Service Dept. / Marketing Dept. / Business Dept. (Manager Post)",
        },
        {
          name: "客服部/市场部/业务部（总监岗及以上）",
          value:
            "客服部/市场部/业务部（总监岗及以上）Customer Service Dept. / Marketing Dept. / Business Dept. (Director Post and above)",
        },
        {
          name: "业务部（专员岗）",
          value: "业务部（专员岗）Business Dept. (Specialist Post)",
        },
        {
          name: "业务部（经理岗）",
          value: "业务部（经理岗）Business Dept. (Manager Post)",
        },
        {
          name: "业务部（总监岗及以上）",
          value:
            "业务部（总监岗及以上）Business Dept. (Director Post and above)",
        },
      ],
      checked:false,
      personCopy: {},
      validateArr: [],
      areaList: areaList,
      fileUrl: "",
      emailRule: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
      cardIdRule:
        /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
      phoneRule:
        /^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$/,
      codeRule: /\d{4}/,
      active: 0,
      date: {
        minDate: new Date(1970, 0, 1),
        maxDate: new Date(),
        currentDate: new Date(),
      }, //年月日对象
      examDateOptions: [],
      examCityOptions: [],
      higEduOptions: [
        "硕士研究生",
        "博士",
        "本科",
        "大专",
        "中专/职技校",
        "高中",
        "其他",
      ],
      examCityIsShow: false,
      examDateIsShow: false,
      gradTimeIsShow: false,
      birthdayIsShow: false,
      cardTypeIsShow: false,
      earaIsShow: false,
      higEduIsShow: false,
      addRegisterIsShow: false,
      updateMessageIsShow: false,
      goExamIsShow: false,
      cardOptions: [
        { id: 1, name: "居民身份证" },
        { id: 2, name: "护照" },
        { id: 3, name: "港澳台胞身份证" },
      ],
      profile: [],
      form: {
        province: null,
        city: null,
        dis:null,
        photo: "",
      },
      oldForm: {},
      examForm: {
        exam_org_code: "", //报考机构
        name: "", //姓名
        last_py: "", //姓拼音
        first_py: "", //名拼音
        card_type: 1, //证件类型
        card_id: "", //证件号码
        birthday: "", //出生日期
        address: "", //家庭住址
        org: {
          org_code: "", //机构代码
        },
        school: "", //毕业学校
        grad_time: "", //毕业时间
        hig_edu: "", //最高学历
        major: "", //专业门类
        com_name: "", //单位名称
        work_duty: "", //现有职务
        work_duty_en: "", //现有职务英文
        work_title: "", //现有职称
        work_age: "0", //从业年限
        course: {
          id: "", //考试级别,
          name: "",
        },
        exam_date: "", //考试时间
        exam_city: "", //考试城市 (薪酬管理师)
        is_train: false, //是否参加培训 (薪酬管理师)
        photo: "", //上传证件照片
        sign: "", //电子签名
        phone: "", //手机号码
        code: "", //手机验证码
        ind_type: "", //行业类型
        com_type: "", //单位类型
      }, //报考表单字段
      person: {
        photo: "",
      }, //个人信息对象
      state_map: {
        0: "机构一审驳回",
        1: "机构一审待审",
        2: "总部一审驳回",
        3: "总部一审待审",
        4: "机构二审驳回",
        5: "机构二审待审",
        6: "总部二审驳回",
        7: "总部二审待审",
        8: "全部审核通过",
      }, //审核状态字典
      isReject: {
        0: "org_1_reject",
        1: "org_1_wait",
        2: "admin_1_reject",
        3: "admin_1_wait",
        4: "org_2_reject",
        5: "org_2_wait",
        6: "admin_2_reject",
        7: "admin_2_wait",
        8: "allpass",
      },
    };
  },
  mounted() {
    // 给 popstate 绑定一个方法 监听页面刷新
    window.addEventListener("popstate", this.wulifanhui, false); //false阻止默认事件
  },
  destroyed() {
    window.removeEventListener("popstate", this.wulifanhui, false); //false阻止默认事件
  },
  methods: {
    wulifanhui() {
      console.log("监听到了");
      if (
        this.addRegisterIsShow == true ||
        this.goExamIsShow == true ||
        this.updateMessageIsShow == true
      ) {
        this.addRegisterIsShow == false;
        this.goExamIsShow == false;
        this.updateMessageIsShow == false;
      }
    },
    isRegisterFun() {
      window.open("/exam_register.html");
    },
    isPrivacyFun() {
      window.open("/exam_privacy.html");
    },
    //合同签署
    toTransation(params) {
      Dialog.confirm({
        title: "标题",
        message: "弹窗内容",
      })
        .then(() => {
          let province = params.province == null ? "" : params.province;
          let city = params.city == null ? "" : params.city;
          let dis = params.dis == null ? "" : params.dis;
          let TransationObj = {
            openid: params.card_id,
            parameter_map: {
              org_name: params.exam_org.org_name,
              course_name: params.course.name,
              time_detail: params.exam_date,
              exam_city: params.exam_city,
              user_name:
                params.name + " " + params.last_py + " " + params.first_py,
              card_type: params.card_type_display,
              card_id: params.card_id,
              gender: params.gender_display,
              birthday: params.birthday,
              hig_edu: params.hig_edu,
              grad_time:
                params.grad_time.split("-")[0] +
                "-" +
                params.grad_time.split("-")[1],
              cert: this.certDisplayOptions.filter(
                (element) => element.id == params.cert
              )[0].name,
              region: province + " " + city + " " + dis,
              work_age: params.work_age + "年",
              com_name: params.com_name,
              email: params.email,
              work_duty: params.work_duty,
              sign: "",
              current_date:
                new Date().getFullYear() +
                "年" +
                (new Date().getMonth() + 1) +
                "月" +
                new Date().getDate() +
                "日",
              type_industry: this.indTypeOptions.filter(
                (element) => element.value == params.ind_type
              )[0].name,
              type_company: this.comTypeOptions.filter(
                (element) => element.value == params.com_type
              )[0].name,
              phone: params.phone,
            },
          };
          console.log(TransationObj);
          generateContract(TransationObj).then((res) => {
            console.log(res);
            params.contract_id = res.contract_id;
            let paramsObj = {
              pid: params.id,
              contract_id: params.contract_id,
            };
            signContract(paramsObj).then((res) => {
              console.log(res);
            });
            window.open(res.sign_url);
          });
        })
        .catch(() => {
          // on cancel
          console.log("未知错误");
        });
    },
    onConfirmArea(value) {
      this.form.province = value[0].name;
      this.form.city = value[1].name;
      this.form.dis = value[2].name;
      this.earaIsShow = false;
      console.log(value);
    },
    onConfirmWorkDuty(value, index) {
      this.form.work_duty = value.value;
      this.work_dutyIsShow = false;
    },
    onConfirmIndType(value, index) {
      this.form.ind_type = value.value;
      this.ind_typeIsShow = false;
    },
    onConfirmComType(value, index) {
      this.form.com_type = value.value;
      this.com_typeIsShow = false;
    },
    onConfirmWorkDutyExam(value, index) {
      this.examForm.work_duty = value.value;
      this.work_dutyIsShow = false;
    },
    onConfirmIndTypeExam(value, index) {
      this.examForm.ind_type = value.value;
      this.ind_typeIsShow = false;
    },
    onConfirmComTypeExam(value, index) {
      this.examForm.com_type = value.value;
      this.com_typeIsShow = false;
    },
    lookTransation(contract_id) {
      viewContract({ contract_id: contract_id }).then((res) => {
        window.open(res.view_url);
      });
    },
    updateSubmit() {
      let params = { pid: this.form.id };
      for (let item in this.oldForm) {
        if (this.form[item] !== this.oldForm[item]) {
          if (
            Object.prototype.toString.call(this.form[item]) ===
            "[object Object]"
          ) {
            continue;
          }
          params[item] = this.form[item];
        }
      }
      let cardObj = {
        card_id: this.form.card_id,
        card_type: this.form.card_type,
        name: this.form.name,
      };
      for (let key in params) {
        if (cardObj.hasOwnProperty(key)) {
          Object.assign(params, cardObj);
        }
      }
      console.log("params", params);
      editContent(params)
        .then((res) => {
          this.getProfile();
          console.log(res);
          Notify({ type: "success", message: "修改成功" });
          this.updateMessageIsShow = false;
        })
        .catch((err) => {
          let resetForm = JSON.parse(JSON.stringify(this.oldForm));
          this.form = resetForm;
          this.person = this.oldForm;
          Notify({ type: "error", message: "修改失败" });
        });
    },
    onConfirmAreaUpdate(value) {
      console.log("修改所在城市", value);
      this.form.province = value[0].name;
      this.form.city = value[1].name;
      this.earaIsShow = false;
    },
    onConfirmHigEdu(value) {
      console.log("最高学历", value);
      this.examForm.hig_edu = value;
      this.higEduIsShow = false;
    },
    onConfirmHigEduUpdate(value) {
      console.log("最高学历", value);
      this.form.hig_edu = value;
      this.higEduIsShow = false;
    },
    onCancelHigEdu() {
      this.higEduIsShow = false;
    },
    onExamFailed() {
      Toast({
        message: "请检查是否漏填字段",
        position: "top",
      });
    },
    vantUpload(value) {
      console.log("接受图片Base64", value);
      this.examForm.photo = value;
    },
    vantUploadUpdate(value) {
      console.log("接受图片Base64", value);
      this.form.photo = value;
    },
    onClickLeft() {
      Dialog.confirm({
        title: "退出",
        message: "是否退出该系统",
      })
        .then(() => {
          this.$cookies.remove("token");
          this.$store.state.token = "";
          location.reload();
        })
        .catch(() => {
          // on cancel
        });
    },
    onClickRight() {
      this.addRegisterIsShow = true;
    },
    handleRegister(option) {
      console.log("报名组件传递参数", option);
      get_n_Org(option)
        .then((res) => {
          Notify({ type: "success", message: "报名成功" });
          this.addRegisterIsShow = false;
          this.getProfile();
        })
        .catch((error) => {
          Notify({ type: "danger", message: error.msg });
        });
    },
    getProfile() {
      getProfile().then((res) => {
        let newRes = this.ReverseRankingDate(res, "update_time");
        console.log("res---", newRes);
        this.profile = newRes;
        // for (let item of newRes) {
        //     item['photo'] = item['photo'] + '?' + Math.round(Math.random() * 100000);
        //     if (item.state_code > 7) {
        //         this.person = item;
        //         this.person['photo'] = item['photo'] + '?' + Math.round(Math.random() * 100000);
        //         return
        //     }
        // }
        // this.person = newRes[newRes.length - 1];
        this.personCopy = JSON.parse(JSON.stringify(newRes[0]));
        for (let item of newRes) {
          for (let key in item) {
            if (item[key] !== null && item[key] !== "") {
              this.personCopy[key] = item[key];
            }
          }
        }
        this.person = this.personCopy;
        console.log("photo", newRes[newRes.length - 1]["photo"]);
        console.log("this.person", this.person);
      });
    },
    //打开编辑表单并赋值
    updateExam(exam_id) {
      this.updateMessageIsShow = true;
      console.log(exam_id);
      console.log("编辑表单内部档案", this.profile);
      for (let item of this.profile) {
        if (item.id == exam_id) {
          this.form = JSON.parse(JSON.stringify(item));
          this.oldForm = JSON.parse(JSON.stringify(this.form));
          console.log("编辑档案item", item);
          // this.selectedOptions.push(TextToCode[this.form.province].code, TextToCode[this.form.province][this.form.city].code);
          this.getExamDate(this.form.course.id);
        }
      }
      console.log("exam_id", exam_id);
    },
    //去报考
    toExam(profile_id) {
      this.active = 0;
      this.goExamIsShow = true;
      let _this = this;
      for (let item of this.profile) {
        this.examForm.last_py = item.last_py;
        this.examForm.first_py = item.first_py;
        this.examForm.school = item.school;
        this.examForm.grad_time = item.grad_time;
        this.examForm.hig_edu = item.hig_edu;
        this.examForm.major = item.major;
        this.examForm.work_age = item.work_age;
        this.examForm.work_title = item.work_title;
        // this.examForm.photo = item.photo;
        this.fileUrl = this.examForm.photo;
        // if (item.state_code == 8) {
        //     this.examForm.last_py = item.last_py;
        //     this.examForm.first_py = item.first_py;
        //     this.examForm.school = item.school;
        //     this.examForm.grad_time = item.grad_time;
        //     this.examForm.hig_edu = item.hig_edu;
        //     this.examForm.major = item.major;
        //     this.examForm.work_age = item.work_age;
        //     this.examForm.work_title = item.work_title;
        //     this.examForm.photo = item.photo;
        //     this.fileUrl = this.examForm.photo;
        // }
        if (item.id === profile_id) {
          this.fileUrl = this.examForm.photo;
          this.examForm.com_name = item.com_name;
          this.examForm.course.id = item.course.id;
          this.examForm.course.name = item.course.name;
          this.examForm.card_type = item.card_type;
          this.examForm.card_id = item.card_id;
          this.examForm.birthday = item.birthday;
          this.examForm.name = item.name;
          this.examForm.address = item.address;
          //   this.examForm.org.org_code = item.org.org_code;
          this.examForm.phone = item.phone;
          this.examForm.work_duty = item.work_duty;
          this.examForm.work_duty_en = item.work_duty_en;
          this.examForm.exam_city = item.exam_city;
          this.examForm.exam_date = item.exam_date;
          this.examForm.ind_type = item.ind_type;
          this.examForm.com_type = item.com_type;
          this.examForm.cert = item.cert;
          this.examForm.card_type_display = item.card_type_display;
          this.examForm.gender_display = item.gender_display;
          this.examForm.province = item.province;
          this.examForm.city = item.city;
          this.examForm.dis = item.dis;
          this.examForm.email = item.email;
          _this.getExamDate(this.examForm.course.id);
          if (this.examForm.course.name.includes("薪酬管理")) {
            this.examForm.is_train = false;
          } else {
            this.examForm.is_train = true;
          }
        }
      }
      console.log("this.examForm", this.examForm);
    },
    //获取考试城市与考试时间(根据课程id)
    getExamDate(course_id) {
      examDateByCourseId(course_id).then((res) => {
        let examCityOption = res.filter((item, index) => {
          return (
            res.findIndex((item1) => item1.exam_city == item.exam_city) == index
          );
        });
        let examDateOption = res.filter((item, index) => {
          return (
            res.findIndex((item1) => item1.exam_date == item.exam_date) == index
          );
        });
        this.examDateOptions = examDateOption;
        this.examCityOptions = examCityOption;
        console.log("考试城市", examDateOption);
        this.form.exam_city = examCityOption[0].exam_city;
        this.form.exam_date = examDateOption[0].exam_date;
        this.examForm.exam_city = examCityOption[0].exam_city;
        this.examForm.exam_date = examDateOption[0].exam_date;
      });
    },
    //步骤上一步
    // pre() {
    //   if (this.active-- < 1) this.active = 0;
    // },
    //步骤下一步
    // next() {
    //   if (this.active == 0) {
    //     // console.log(this.$refs['examForm']);
    //     this.$refs["examForm"]
    //       .validate([
    //         "last_py",
    //         "first_py",
    //         "address",
    //         "school",
    //         "grad_time",
    //         "hig_edu",
    //         "major",
    //       ])
    //       .then((res) => {
    //         if (this.active++ > 1) this.active = 2;
    //       });
    //   }
    //   if (this.active == 1) {
    //     // console.log(this.$refs['examForm']);
    //     this.$refs["examForm"]
    //       .validate([
    //         "com_name",
    //         "work_title",
    //         "work_duty",
    //         "work_duty_en",
    //         "work_age",
    //       ])
    //       .then((res) => {
    //         if (this.active++ > 1) this.active = 2;
    //       });
    //   }
    // },
    onConfirmCardType(value, index) {
      console.log(`证件类型当前值${value.id}`);
      this.examForm.card_type = value.id;
      this.cardTypeIsShow = false;
    },
    onConfirmCardTypeUpdate(value, index) {
      console.log(`证件类型当前值${value.id}`);
      this.form.card_type = value.id;
      this.cardTypeIsShow = false;
    },
    onCancelCardType() {
      this.cardTypeIsShow = false;
    },
    onConfirmBirthday(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`出生日期当前值${value2}`);
      this.examForm.birthday = value2;
      this.birthdayIsShow = false;
    },
    onConfirmBirthdayUpdate(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`出生日期当前值${value2}`);
      this.form.birthday = value2;
      this.birthdayIsShow = false;
    },
    onCancelBirthday() {
      this.birthdayIsShow = false;
    },
    onConfirmGradTime(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`毕业时间当前值${value2}`);
      this.examForm.grad_time = value2;
      this.gradTimeIsShow = false;
    },
    onConfirmGradTimeUpdate(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`毕业时间当前值${value2}`);
      this.form.grad_time = value2;
      this.gradTimeIsShow = false;
    },
    onCancelExamDate() {
      this.gradTimeIsShow = false;
    },
    onConfirmExamDate(value) {
      this.examForm.exam_date = value.exam_date;
      console.log("考试时间", value);
      this.examDateIsShow = false;
    },
    onConfirmExamDateUpdate(value) {
      this.form.exam_date = value.exam_date;
      console.log("考试时间", value);
      this.examDateIsShow = false;
    },
    onConfirmExamCity(value) {
      this.examForm.exam_city = value.exam_city;
      console.log("考试城市", value);
      this.examCityIsShow = false;
    },
    onConfirmExamCityUpdate(value) {
      this.form.exam_city = value.exam_city;
      console.log("考试城市", value);
      this.examCityIsShow = false;
    },
    test() {
      this.$refs["examForm"].validate().then((res) => {
        this.validateArr = res;
      });
    },
    onExamSubmit() {
      if (this.examForm.exam_org_code !== "") {
        console.log(this.examForm.exam_org_code);
        let orgCode = this.examForm.exam_org_code;
        getOrg(orgCode)
          .then((res) => {
            if (true) {
              this.examForm["course_id"] = this.examForm.course.id;
              this.examForm["org_code"] = this.examForm.exam_org_code;
              // this.examForm["exam_code"] = this.examForm.org.org_code;
              console.log(this.examForm, "通过");
              console.log(res);
              console.log(
                this.certDisplayOptions.filter(
                  (element) => element.id == this.examForm.cert
                )[0]
              );
              let province =
                      this.examForm.province == null
                        ? ""
                        : this.examForm.province;
                    let city =
                      this.examForm.city == null ? "" : this.examForm.city;
                    let dis =
                      this.examForm.dis == null ? "" : this.examForm.dis;
              let params = {
                openid: this.examForm.card_id,
                parameter_map: {
                  org_name: res.org_name,
                  course_name: this.examForm.course.name,
                  time_detail: this.examForm.exam_date,
                  exam_city: this.examForm.exam_city,
                  user_name:
                    this.examForm.name +
                    " " +
                    this.examForm.last_py +
                    this.examForm.first_py,
                  card_type: this.examForm.card_type_display,
                  card_id: this.examForm.card_id,
                  gender: this.examForm.gender_display,
                  birthday: this.examForm.birthday,
                  hig_edu: this.examForm.hig_edu,
                  grad_time: this.examForm.grad_time.split('-')[0]+'-'+this.examForm.grad_time.split('-')[1],
                  cert: this.certDisplayOptions.filter(
                    (element) => element.id == this.examForm.cert
                  )[0].name,
                  region:province + " " + city + " " + dis,
                  work_age: this.examForm.work_age + "年",
                  com_name: this.examForm.com_name,
                  email: this.examForm.email,
                  work_duty: this.examForm.work_duty,
                  sign: "",
                  current_date:
                    new Date().getFullYear() +
                    "年" +
                    (new Date().getMonth() + 1) +
                    "月" +
                    new Date().getDate() +
                    "日",
                  type_industry: this.indTypeOptions.filter(
                    (element) => element.value == this.examForm.ind_type
                  )[0].name,
                  type_company: this.comTypeOptions.filter(
                    (element) => element.value == this.examForm.com_type
                  )[0].name,
                  phone: this.examForm.phone,
                },
              };
              console.log(params.parameter_map);
              let ContractUrl = "";
              generateContract(params).then((res) => {
                console.log("合同填充返回数据", res);
                ContractUrl = res.sign_url;
                this.examForm.contract_id = res.contract_id;
                let paramsObj = {
                  pid: params.id,
                  contract_id: this.examForm.contract_id,
                };
                signContract(paramsObj).then((res) => {
                  console.log(res);
                });
                exam_reg(this.examForm)
                  .then((res) => {
                    console.log(res);
                    this.$message({
                      type: "success",
                      message: "提交成功",
                    });
                    window.open(ContractUrl);
                    this.toExamisShow = false;
                    this.getProfile();
                  })
                  .catch((err) => {
                    this.$refs["captcha"].isShow = true;
                    console.log("catch", err);
                    Notify({ type: "danger", message: err.msg });
                  });
              });
            }
          })
          .catch((err) => {
            console.log(err);
            Notify({ type: "danger", message: "机构不存在" });
          });
      }
    },
    ReverseRankingDate(data, p) {
      for (let i = 0; i < data.length - 1; i++) {
        for (let j = 0; j < data.length - 1 - i; j++) {
          // console.log(Date.parse(data[j][p]));
          if (Date.parse(data[j][p]) > Date.parse(data[j + 1][p])) {
            var temp = data[j];
            data[j] = data[j + 1];
            data[j + 1] = temp;
          }
        }
      }
      return data;
    },
    toGrade() {
      this.$router.push("/grade");
    },
  },
  created() {
    this.getProfile();
  },
  computed: {
    course_name() {
      if (this.registerForm.course_id !== "") {
        let course_name = "";
        for (let item of this.courseList) {
          if (item.id == this.registerForm.course_id) {
            console.log(item);
            console.log("item.examdate", item.examdate);
            this.exam_cityOptions = item.examdate;
            course_name = item.name;
          }
        }
        return course_name;
      }
      return "";
    },
    indTypeName() {
      let indTypeName = "";
      for (let item of this.indTypeOptions) {
        if (item.value == this.form.ind_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          indTypeName = item.name;
        }
      }
      return indTypeName;
    },
    work_dutyName() {
      let work_dutyName = "";
      for (let item of this.workDutyOptions) {
        if (item.value == this.form.work_duty) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          work_dutyName = item.name;
        }
      }
      return work_dutyName;
    },
    comTypeName() {
      let comTypeName = "";
      for (let item of this.comTypeOptions) {
        if (item.value == this.form.com_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          comTypeName = item.name;
        }
      }
      return comTypeName;
    },
    indTypeNameExam() {
      let indTypeNameExam = "";
      for (let item of this.indTypeOptions) {
        if (item.value == this.examForm.ind_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          indTypeNameExam = item.name;
        }
      }
      return indTypeNameExam;
    },
    work_dutyNameExam() {
      let work_dutyNameExam = "";
      for (let item of this.workDutyOptions) {
        if (item.value == this.examForm.work_duty) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          work_dutyNameExam = item.name;
        }
      }
      return work_dutyNameExam;
    },
    comTypeNameExam() {
      let comTypeNameExam = "";
      for (let item of this.comTypeOptions) {
        if (item.value == this.examForm.com_type) {
          console.log("报考计算属性");
          // this.exam_cityOptions = item.examdate
          comTypeNameExam = item.name;
        }
      }
      return comTypeNameExam;
    },
    cardTypeUpdate() {
      let cardTypeName = "默认值";
      for (let item of this.cardOptions) {
        if (item.id == this.form.card_type) {
          console.log("证件类型---", item);
          // this.exam_cityOptions = item.examdate
          cardTypeName = item.name;
          console.log(cardTypeName);
        }
      }
      return cardTypeName;
    },
    cardTypeUpdate() {
      let cardTypeName = "默认值";
      for (let item of this.cardOptions) {
        if (item.id == this.form.card_type) {
          console.log("证件类型---", item);
          // this.exam_cityOptions = item.examdate
          cardTypeName = item.name;
          console.log(cardTypeName);
        }
      }
      return cardTypeName;
    },
    cardType() {
      let cardTypeName = "默认值";
      for (let item of this.cardOptions) {
        if (item.id == this.examForm.card_type) {
          console.log("证件类型---", item);
          // this.exam_cityOptions = item.examdate
          cardTypeName = item.name;
          console.log(cardTypeName);
        }
      }
      return cardTypeName;
    },
    //设置头像
    // squareUrl() {
    //     if (!this.person.photo.includes('null')) {
    //         return this.person.photo;
    //     }
    //     return "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png";
    // },
  },
  components: {
    registerForm,
    vantImgUpload,
    TencentCaptcha,
  },
};
</script>

<style scoped>
.icon-zhengshu1:before {
  font-size: 48px;
  color: rgb(55, 189, 196);
}

.icon-chengjidan:before {
  font-size: 48px;
  color: rgb(90, 194, 238);
}

.search {
  margin-top: 10px;
  color: #969799;
}

.personMessage {
  width: 90%;
  margin: 10px auto;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  border-bottom: 0.5px solid #bbbbbb;
}

.footer {
  width: 90%;
  margin: 10px auto;
  font-size: 14px;
  line-height: 20px;
}

.personMessage .header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.personMessage .header .left-Message {
  width: 70%;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.person {
  margin-top: 10px;
  border: 1px solid #f0f0f0;
  box-shadow: 5px 10px 10px rgb(0 0 0 / 5%);
}

.profileCard {
  margin-top: 10px;
}

.examTitle {
  font-size: 1.1em;
  font-weight: 700;
}

.headTitle {
  background-color: gainsboro;
}

.headTitle i {
  margin-left: 5px;
}

.headTitle span {
  margin-left: 5px;
}

.examModel {
  margin-bottom: 10px;
}

.examCourseName {
  font-size: 10px;
}
.examButton {
  margin: 20px auto;
  width: 50%;
  display: flex;
  justify-content: space-around;
}
</style>
